package com.example.result.books

import android.content.Context
import androidx.annotation.Keep
import androidx.datastore.core.DataStore
import androidx.datastore.dataStore
import com.example.result.BaseSerializer
import kotlinx.serialization.Serializable

@Keep
@Serializable
data class BookMarks(val bookMarks: List<String> = emptyList())

@Keep
@Serializable
data class SectionPatterns(val patterns: List<String> = arrayListOf("\n+(?=\\s*第.{1,6}[章节].{0,20}\\s*\n)"))

@Keep
@Serializable
data class RecordInfo(val key: String, val value: String)

@Keep
@Serializable
data class TextEncodeRecord(val data: List<RecordInfo> = emptyList())

@Keep
@Serializable
data class TextSectionPatternRecord(val data: List<RecordInfo> = emptyList())

@Keep
@Serializable
data class BookSortInfo(
    val sortType: String = SortType.Desc.name,
    val sortCategory: String = SortCategory.Name.name
)

@Keep
@Serializable
data class FileTypeMap(
    val map: Map<String, String> = mapOf(
        "md" to com.lly.tboc.zhouyi.Screen.FileType.Markdown.name,
        "dot" to com.lly.tboc.zhouyi.Screen.FileType.Dot.name,
        "txt" to com.lly.tboc.zhouyi.Screen.FileType.Txt.name,
        "svg" to com.lly.tboc.zhouyi.Screen.FileType.Svg.name,
        "jpg" to com.lly.tboc.zhouyi.Screen.FileType.Bitmap.name,
        "jp" to com.lly.tboc.zhouyi.Screen.FileType.Bitmap.name,
        "png" to com.lly.tboc.zhouyi.Screen.FileType.Bitmap.name,
    )
)

val Context.bookMarksDataStore: DataStore<BookMarks> by dataStore(
    fileName = "bookMarks.pb",
    serializer = BaseSerializer(BookMarks(), BookMarks.serializer())
)
val Context.recentExplorerDataStore: DataStore<BookMarks> by dataStore(
    fileName = "recentExplorer.pb",
    serializer = BaseSerializer(BookMarks(), BookMarks.serializer())
)
val Context.recentBookSortDataStore: DataStore<BookSortInfo> by dataStore(
    fileName = "bookSort.pb",
    serializer = BaseSerializer(BookSortInfo(), BookSortInfo.serializer())
)
val Context.fileTypeMapDataStore: DataStore<FileTypeMap> by dataStore(
    fileName = "fileTypeMap.pb",
    serializer = BaseSerializer(FileTypeMap(), FileTypeMap.serializer())
)
val Context.sectionPatternsDataStore: DataStore<SectionPatterns> by dataStore(
    fileName = "SectionPatterns.pb",
    serializer = BaseSerializer(SectionPatterns(), SectionPatterns.serializer())
)
val Context.textEncodeRecodeDataStore: DataStore<TextEncodeRecord> by dataStore(
    fileName = "TextEncodeRecode.pb",
    serializer = BaseSerializer(TextEncodeRecord(), TextEncodeRecord.serializer())
)
val Context.textSectionPatternRecordDataStore: DataStore<TextSectionPatternRecord> by dataStore(
    fileName = "TextSectionPatternRecord.pb",
    serializer = BaseSerializer(TextSectionPatternRecord(), TextSectionPatternRecord.serializer())
)